package com.example.shirospringboottest.service.impl;

import com.example.shirospringboottest.mapper.UserMapper;
import com.example.shirospringboottest.pojo.User;
import com.example.shirospringboottest.pojo.UserExample;
import com.example.shirospringboottest.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User login(User user) {

        UserExample userExample = new UserExample();

        UserExample.Criteria criteria = userExample.createCriteria();

        criteria.andUserNameEqualTo(user.getUserName());

        List<User> userList = this.userMapper.selectByExample(userExample);

        if (userList.size() == 1) {
            return userList.get(0);
        }

        return null;
    }
}
